package com.max.mil.fuwu.controller;

import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.max.mil.common.util.DataPage;
import com.max.mil.common.util.StringUtil;
import com.max.mil.fuwu.model.vo.Full;
import com.max.mil.fuwu.service.FullService;
import com.max.mil.fuwu.service.ProdService;
import com.max.mil.fuwu.service.impl.FullServiceImpl;
import com.max.mil.fuwu.service.impl.ProdServiceImpl;

@Controller
@RequestMapping("/full")
public class FullController
{
	
	FullService fullService = new FullServiceImpl();
	ProdService prodService = new ProdServiceImpl();
	
	
	@RequestMapping("/fullList")
	public String fullList(Integer status, Integer pageNo, Integer pageSize, Model model) throws Exception 
	{
		if(status == null) status = -1;
		if(pageNo == null) pageNo = 1;
		if(pageSize == null) pageSize = 10;
		
		DataPage<Full> dp = fullService.getFullList(status!=null?status:-1, pageNo!=null?pageNo:1, pageSize!=null?pageSize:10);
		model.addAttribute("dp", dp);
		
		return "full/fullList";
	}
	
	@RequestMapping("/fullEditS1")
	public String fullEditS1() throws Exception 
	{
		return "full/fullEditS1";
	}
	
	@RequestMapping("/fullEditS2")
	public String fullEditS2(String id, String title, Integer range, Integer repeat, Integer limit, Integer joinLevel, 
			String condition, String content, Date effectTime, Date expireTime, Model model) throws Exception 
	{
		condition = "100,200;10,21";
		
		/**1.促销模板信息*/
		Full full = new Full();
		full.setId(id);
		full.setTitle(title);
		full.setRange(range!=null?range:1);
		full.setRepeat(repeat!=null?repeat:0);
		full.setLimit(limit!=null?limit:0);
		full.setJoinLevel(joinLevel!=null?joinLevel:1);
		full.setCondition(condition);
		full.setContent(content);
		full.setEffectTime(effectTime);
		full.setExpireTime(expireTime);
		
		/**2.1.提交第1步*/
		if(StringUtil.isEmpty(full.getContent()))
		{
			if(!StringUtil.isEmpty(full.getId()))
				full = fullService.getFull(id);
			
			model.addAttribute("full", full);
			return "full/fullEditS2";
		}
		/**2.2.提交第2步*/
		else
		{
			if(!StringUtil.isEmpty(id))
				fullService.delFull(id);
			id = fullService.addFull(full);
			
			model.addAttribute("full", full);
			return "forward:fullList.do";
		}
	}
}
